package czk.concrent.threadpool.future;

import java.util.concurrent.*;

/**
 * isDone判断线程池内容是否返回
 *
 * @Author:ChenZhangKun
 * @Date: 2021/9/30 11:55
 */
public class FutureIsDone {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService threadPool = Executors.newFixedThreadPool(2);
        //2 利用calllable来获取异常
        Future<Integer> f = threadPool.submit(() -> {
            TimeUnit.SECONDS.sleep(1);
            return 2;
        });
        while (!f.isDone()) {
            System.out.println(System.currentTimeMillis() + " 还没结束");
        }
        Integer integer = f.get();// 此时会打印异常
        System.out.println(integer);
        threadPool.shutdown();
    }
}
